package o;

import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.bean.startup.StartupResponse.TabInfo;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class ejn {
    private static final Object ˋ = new Object();
    private static ejn ˏ;
    private HashMap<String, ArrayList<TabInfo>> ˊ = new HashMap();
    private HashMap<String, ArrayList<TabInfo>> ॱ = new HashMap();

    public static ejn ˋ() {
        ejn o_ejn;
        synchronized (ˋ) {
            if (ˏ == null) {
                ˏ = new ejn();
            }
            o_ejn = ˏ;
        }
        return o_ejn;
    }

    @Nullable
    public ArrayList<TabInfo> ˋ(String str) {
        if (TextUtils.isEmpty(str) || this.ˊ == null) {
            return null;
        }
        return (ArrayList) this.ˊ.get(str);
    }

    public void ˊ(String str, ArrayList<TabInfo> arrayList) {
        Logger.ˏ("SubTabDataManager", "putData uri = " + str);
        if (!dof.ˋ(str)) {
            if (CollectCheck.isEmpty((List) arrayList)) {
                this.ˊ.remove(str);
                return;
            }
            ArrayList arrayList2 = new ArrayList();
            arrayList2.addAll(arrayList);
            this.ˊ.put(str, arrayList2);
        }
    }

    public void ˏ(String str, ArrayList<TabInfo> arrayList) {
        Logger.ˏ("SubTabDataManager", "saveDefaultSubTabList uri = " + str);
        if (!dof.ˋ(str)) {
            if (CollectCheck.isEmpty((List) arrayList)) {
                this.ॱ.remove(str);
                return;
            }
            ArrayList arrayList2 = new ArrayList();
            arrayList2.addAll(arrayList);
            this.ॱ.put(str, arrayList2);
        }
    }

    public void ॱ(String str) {
        if (!TextUtils.isEmpty(str)) {
            this.ˊ.remove(str);
            if (!CollectCheck.isEmpty(this.ॱ)) {
                List list = (ArrayList) this.ॱ.get(str);
                if (!CollectCheck.isEmpty(list)) {
                    ArrayList arrayList = new ArrayList();
                    arrayList.addAll(list);
                    this.ˊ.put(str, arrayList);
                }
            }
        }
    }

    @Nullable
    private String ˎ(String str) {
        if (this.ˊ == null) {
            Logger.ˋ("SubTabDataManager", "getCatSortStr dataMap null");
            return null;
        } else if (TextUtils.isEmpty(str)) {
            return null;
        } else {
            return ॱ((ArrayList) this.ˊ.get(str));
        }
    }

    private String ॱ(ArrayList<TabInfo> arrayList) {
        if (CollectCheck.isEmpty((List) arrayList)) {
            return null;
        }
        StringBuilder stringBuilder = new StringBuilder(256);
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            stringBuilder.append(((TabInfo) it.next()).ʼ()).append(",");
        }
        String stringBuilder2 = stringBuilder.toString();
        return stringBuilder2.substring(0, stringBuilder2.length() - 1);
    }

    public void ॱ(@NonNull final String str, int i) {
        String ˎ = ˋ().ˎ(str);
        if (!dof.ˋ(ˎ)) {
            cvt o_ejo = new ejo();
            o_ejo.ˏ(str);
            o_ejo.ˎ(ˎ);
            o_ejo.setServiceType_(i);
            cfw.ˎ(o_ejo, new IServerCallBack(this) {
                final /* synthetic */ ejn ˊ;

                public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
                    if (responseBean.getRtnCode_() == 0 && responseBean.getResponseCode() == 0) {
                        euh.ˏ().ʼ(str);
                        return;
                    }
                    List list = (ArrayList) this.ˊ.ˊ.get(str);
                    if (!CollectCheck.isEmpty(list)) {
                        JSONArray jSONArray = new JSONArray();
                        Iterator it = list.iterator();
                        while (it.hasNext()) {
                            try {
                                jSONArray.put(new JSONObject(((TabInfo) it.next()).toJson()));
                            } catch (IllegalAccessException e) {
                                Logger.e("SubTabDataManager", e.toString());
                            } catch (JSONException e2) {
                                Logger.e("SubTabDataManager", e2.toString());
                            }
                        }
                        String jSONArray2 = jSONArray.toString();
                        euh.ˏ().ˋ(str, jSONArray2);
                        Logger.ˋ("SubTabDataManager", "cache subtab list dataJsonStr=" + jSONArray2);
                    }
                }

                public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
                }
            });
        }
    }

    @Nullable
    public ArrayList<TabInfo> ˊ(String str) {
        ArrayList<TabInfo> arrayList = null;
        if (!TextUtils.isEmpty(str)) {
            Object ॱ = euh.ˏ().ॱ(str, "");
            if (!TextUtils.isEmpty(ॱ)) {
                arrayList = new ArrayList();
                try {
                    JSONArray jSONArray = new JSONArray(ॱ);
                    for (int i = 0; i < jSONArray.length(); i++) {
                        JSONObject jSONObject = jSONArray.getJSONObject(i);
                        TabInfo tabInfo = new TabInfo();
                        tabInfo.fromJson(jSONObject);
                        arrayList.add(tabInfo);
                    }
                } catch (JSONException e) {
                    Logger.e("SubTabDataManager", e.toString());
                } catch (IllegalAccessException e2) {
                    Logger.e("SubTabDataManager", e2.toString());
                } catch (InstantiationException e3) {
                    Logger.e("SubTabDataManager", e3.toString());
                } catch (ClassNotFoundException e4) {
                    Logger.e("SubTabDataManager", e4.toString());
                }
            }
        }
        return arrayList;
    }
}
